<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>v-model 修饰符</title>
    <script src="/vue.js"></script>
  </head>
  <body>
    <div id="app">
      <form action="javascript:;">
        <!-- v-model.trim 修饰符在收集表单中的数据是会去掉前后空格 -->
        <label for="username">用户名: </label>
        <input type="text" id="username" v-model.trim="loginData.username" />

        <!-- v-model.lazy 将表单的的实时数据，改为失去焦点时收集类似于 onChange (oninput事件是在元素值发生变化时立即触发，而onchange事件是在元素失去焦点时触发) -->
        <label for="password">密码: </label>
        <input type="text" id="password" v-model.lazy="loginData.password" />

        <!-- v-model.number 收集数据的时候直接转为number类型,如果无法转为正常的数字,则保持原来的字符串格式 -->
        <label for="age">年龄: </label>
        <input type="text" id="age" v-model.number="loginData.age" />
      </form>
    </div>
    <script>
      Vue.config.productionTip = false;
      const vm = new Vue({
        el: "#app",
        data() {
          return {
            loginData: {
              username: "",
              password: "",
              age: null,
            },
          };
        },
      });
    </script>
  </body>
</html>
